<?php
	include_once( 'core_Door.php' );
	include_once( 'core_ErrorCode.php' );
	include_once( 'core_DataBaseConnect.php' );
	include_once( 'core_Response.php' );
	include_once( 'dao_MemberDAO.php' );
	include_once( 'dao_ServiceConfigure.php' );
	include_once( '_configs.php' );
	
	// 반환 유형 예외
	if( $_POST[ '__returnType__' ] )
		$returnType = $_POST[ '__returnType__' ];
	else
		$returnType = Response::RETURN_TYPE_XML;
	
	// 헤더 컨텐츠 타입
	if( strtolower( $returnType ) == Response::RETURN_TYPE_XML )
	{
		header('Content-Type: application/xml');
		$strEcho = '<?xml version="1.0" encoding="utf-8"?>';
	}else if( strtolower( $returnType ) == Response::RETURN_TYPE_JSON )
	{
		header('Content-Type: application/json');
		$strEcho = '';
	}
	
	
	// DB 객체 생성
	$con = new DataBaseConnect();
	try{
		$con->connect( configs::DATABASE_HOST, configs::DATABASE_USERNAME, configs::DATABASE_PASS, configs::DATABASE_DBNAME );
	}catch( Exception $e )
	{
		// 접속 실폐
		echo Response::FAIL( ErrorCode::FAIL_DATABASE_CONNET, "데이터 베이스 접속에 오류입니다.".$e->getMessage(), $returnType );
		exit;
	}
	
	// 서버 점검 체크
	$result = ServiceConfigure::isServerLock( $con );
	if( $fetch = DataBaseConnect::fetch_assoc( $result ) )
	{
		$message = $fetch[ 'MESSAGE' ].'('.$fetch[ 'START' ].'~'.$fetch[ 'END' ].')';
		echo Response::FAIL( ErrorCode::SERVER_LOCKING, "서버 점검중입니다.".$message, $returnType );
		$con->close();
		exit;
	}
	
	// 세션 체크
	/*
	if( $_POST[ 'login_member_id' ] != '' )
	{
		if( MemberDAO::isCheckSessionID( $con, $_POST[ 'login_member_id' ], $_POST[ 'login_member_session' ] ) == false )
		{
			// 세션 오류
			echo Response::FAIL( ErrorCode::NOT_MATCH_SESSION, "세션을 잃었습니다. 다시 로그인해주세요.", $returnType );
			$con->close();
			exit;
		}
	}
	*/
	$__key__;
	if( $_GET[ '__key__' ] )
	{
		$__key__ = $_GET[ '__key__' ];
	}else{
		$__key__ = $_POST[ '__key__' ];
	}
	
	
	// BODY 실행
	if( $__key__ == '_traceParam' )
	{
		include_once( $__key__.'.php' );
	}else{
		include_once( 'z_'.$__key__.'.php' );
	}
	
	
	echo $strEcho.func( $con, $_POST, $returnType );
	$con->close();
	exit;
?>